package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.user.domain.dto.SetRolePermissionsDTO;
import com.hmall.user.domain.po.SysRolePermissions;
import com.hmall.user.service.SysRolePermissionsService;
import com.hmall.user.mapper.SysRolePermissionsMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author yangfeng
* @description 针对表【sys_role_permissions】的数据库操作Service实现
* @createDate 2024-12-17 16:36:29
*/
@Service
public class SysRolePermissionsServiceImpl extends ServiceImpl<SysRolePermissionsMapper, SysRolePermissions>
    implements SysRolePermissionsService{

    @Override
    public Boolean setPermissions(SetRolePermissionsDTO dto) {
        List<Integer> permissionIds = dto.getPermissionIds();
        LocalDateTime now = LocalDateTime.now();
        List<SysRolePermissions> rolePermissions = permissionIds.stream().map(p -> {
            SysRolePermissions t = new SysRolePermissions();
            t.setPermissionId(p);
            t.setRoleId(dto.getRoleId());
            t.setGrantedAt(now);
            return t;
        }).collect(Collectors.toList());
        return saveBatch(rolePermissions);
    }
}




